﻿Imports System.Collections.Generic

Module Module1

    Sub Main()
        'Dim alst As ArrayList

        'alst = New ArrayList(5)

        'For i As Integer = 0 To 10

        '    alst.Add(i)
        'Next


        'For Each a In alst

        '    Console.WriteLine(a)
        'Next

        'Dim c As Child = New Child
        'c.sub1()
        'c.sub2()
        'c.sub2("hello world")


        Dim c2 As Base = New Child
        c2.sub1()
        c2.sub2() '这个没有被重写
        c2.sub3() '这个没有被重写


        Dim c3 As New Child2
        c3.sub1()
        c3.sub2()
        c3.sub3()


        Console.ReadKey()

    End Sub

    Public Class Base

        Public Sub New()

        End Sub

        '可以被重写
        Public Overridable Sub sub1()

            Console.WriteLine("base:sub1")
        End Sub

        ' 这个不可以被重写
        Public Sub sub2()
            Console.WriteLine("base:sub2")
        End Sub

        Public Sub sub3()
            Console.WriteLine("base:sub3")
        End Sub

    End Class

    Public Class Child
        Inherits Base

        ' 重写父类的方法
        Public Overrides Sub sub1()
            Console.WriteLine("child:sub1")

        End Sub


        Public Sub sub3()
            Console.WriteLine("child:sub3")
        End Sub


        ' 重载的方法
        Public Overloads Sub sub2()
            Console.WriteLine("child:sub2")
        End Sub

        Public Overloads Sub sub2(ByVal a As String)
            Console.WriteLine("child:sub2:{0}", a)
        End Sub

    End Class

    Public Class Child2
        Inherits Base

        Private _name As String
        Private _snary As Double

        Public Property Name As String
            Get
                Return _name
            End Get
            Set(value As String)
                _name = value
            End Set
        End Property

        Public ReadOnly Property Version As String
            Get
                Return "1.1"
            End Get
        End Property


        Public WriteOnly Property Snary As Double
            Set(value As Double)
                _snary = value
            End Set
        End Property

    End Class

End Module
